== Description of VIC20 BASIC Code for VC3 2021 Christmas tree program ==

The VIC 20 has a default screen width of 22 columns times 23 lines. Since the Christmas tree is 23 characters wide, it does not fit onto the VIC's screen. Luckily, it is possible to adjust the number of displayed columns in the VIC Chip register at $9002 and adding one column at the cost of a smaller border easily fits on the screen. This is done with the first command, POKE36866,151. However, the operating system still believes the screen is 22 characters wide so that the carriage return code doesn't work as expected anymore. Therefore, the program outputs all the characters necessary to display the tree in a continuous stream of characters without any newlines. 

The widths of the Christmas tree are 1,3,5,7,3,7,11,15,5,11,17,23,3,3. While a nested loop can calculate the first 12 numbers, I found it shorter to store the numbers in a DATA statement. Since all numbers are uneven, storing halved numbers is sufficient to reconstruct the original width. This makes it also easier to calculate the necessary indentation. We can save further on length by decreasing all numbers until we have a maximum of zeroes since a 0 can be encoded by just a comma in a data statement. The changed number needs to be accounted for at three points of the program: at the left indentation, done with SPC(), the FOR..NEXT loop printing the stars, and the spaces on the right side, done with another SPC().

The program has two lines packed with code and can be entered on the native system. The program loops with a GOTO command. The program ends with an OUT OF DATA ERROR when the READ command runs out of data. 

Abbreviated code (for minimal number of characters when entering):

0pO36866,151:?"S";:dA-1,,1,2,,2,4,6,1,4,7,10,,
1rEw:?sP10-w);:fOk=-2tow+w:?"*";:nE:?sP10-w);:gO1

Note that the "S" does not denote an uppercase S, but a clr key, to be entered with shift+clr/home. 

Expanded code:

0 poke36866,151:print"S";:data-1,,1,2,,2,4,6,1,4,7,10,,
1 readw:printspc(10-w);:fork=-2tow+w:print"*";:next:printspc(10-w);:goto1

After running, the screen width is set to 23 characters, hence misaligned with the operating system routines. To reset the screen format back to 22 columns, type POKE36866,150

The last line contains some garbage because the screen with extended columns is larger than the operating system expects. For this reason, the Kernal routine "forgets" to clean this memory area.









